//
//  LMTools.swift
//  lsnetchatplugin
//
//  Created by yunxiwangluo on 2020/5/18.
//

import UIKit

class LMTools {
    
    // MARK: 字典转字符串
      static func dicValueString(_ dic:[String : Any]) -> String?{
            let data = try? JSONSerialization.data(withJSONObject: dic, options: [])
            let str = String(data: data!, encoding: String.Encoding.utf8)
            return str
        }

    // MARK: 字符串转字典
      static func stringValueDic(_ str: String) -> [String : Any]?{
            let data = str.data(using: String.Encoding.utf8)
            if let dict = try? JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as? [String : Any] {
                return dict
            }
            return nil
        }
    
    //处理success返回给flutter
    //des:描述
    static func resultSuccessToFlutter(des: String)->Dictionary<String,Any>{
        
           return [
               "code": 0,
               "message": des
           ]
              
       }
    

    //处理error返回给flutter
    static func resultErrorToFlutter(error: Error)->Dictionary<String,Any>{
              
           let e: NSError = error as NSError
           
           let errorDes: String = e.userInfo["NSLocalizedDescription"] as? String ?? "";
           
           return [
                "code": e.code,
               "message": errorDes
           ]
              
       }
    
}
